package cuit.game.service;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;


import cuit.game.dao.ApplicationRespository;
import cuit.game.entity.Application;


import jakarta.transaction.Transactional;

@Service
@Transactional
public class ApplicationService {
	@Autowired
	ApplicationRespository applicationRespository;
	/**
     * 查找所有
     * @return
     */
    public List<Application> findByTeam_id(Long team_id){
    	return applicationRespository.findByTeam_id(team_id);
    }
    /**
     * 查找所有
     * @return
     */
    public List<Application> findByUser_id(Long user_id){
    	return applicationRespository.findByUser_id(user_id);
    }
    /**
     * 分页查找
     * 
     * @return
     */
	public Page<Application> findAllByPage(int pageIndex, int pageSize) {
		//排序
		Sort sort = Sort.by(Sort.Direction.ASC, "id");
		//分页
		Pageable pageable = PageRequest.of(pageIndex, pageSize, sort);
		//分页查询
		Page<Application> applicationPage = applicationRespository.findAll(pageable);
		return applicationPage;
	}

	public void save(Application application) {
		applicationRespository.save(application);
	}

	public void deleteById(long id) {

		applicationRespository.deleteById(id);
	}

	public Application findById(long id) {
		return applicationRespository.findById(id).get();
	}
}
